﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using LitJson;
namespace Model
{
    [ObjectEvent]
    public class ConfigComponentEvet : ObjectEvent<ConfigComponent>, IAwake<string>
    {
        public void Awake(string path)
        {
            Get().Awake(path);
        }
    }

    /// <summary>
    /// 配置信息组件
    /// </summary>
    public class ConfigComponent : Component
    {
        private Dictionary<string, string> config = new Dictionary<string, string>();

        public void Awake(string path)
        {
            string json = File.ReadAllText(path);

            config = JsonMapper.ToObject<Dictionary<string, string>>(json);

            if(config == null)
            {
                Log.Error("AppConfig 加载失败！！！");
            }
        }

        public string this[string key]
        {
            get
            {
                return config[key];
            }
        }

    }
}